#include "qjsonobject.h"
#include <QJsonArray>
#include <QString>
#include <QStringList>

#ifndef DEPT_H
#define DEPT_H

#endif // DEPT_H
class Dept{
public:
    QString     createBy;
    QString     createTime;
    QString     updateBy;
    QString     updateTime;
    QString     remark;
    int         deptId;
    int         parentId;
    QString     ancestors;
    QString     deptName;
    int         orderNum;
    QString     leader;
    QString     phone;
    QString     email;
    QString     status;
    int         delFlag;
    QString     parentName;
    QList<Dept>     children;

    QJsonObject toJsonObject(){
        QJsonObject obj;
        obj.insert("createBy",createBy);
        obj.insert("createTime",createTime);
        obj.insert("updateBy",updateBy);
        obj.insert("updateTime",updateTime);
        obj.insert("remark",remark);
        obj.insert("deptId",deptId);
        obj.insert("parentId",parentId);
        obj.insert("ancestors",ancestors);
        obj.insert("deptName",deptName);
        obj.insert("orderNum",orderNum);
        obj.insert("leader",leader);
        obj.insert("phone",phone);
        obj.insert("email",email);
        obj.insert("status",status);
        obj.insert("delFlag",delFlag);
        obj.insert("parentName",parentName);
        QJsonArray arrChildren;
        for(int i = 0;i< children.size();i++){
            arrChildren.append(children[i].toJsonObject());
        }
        obj.insert("children",arrChildren);
        return obj;
    }

    static Dept toDept(QJsonObject deptObj) {
        Dept dept;
        if (deptObj.contains("createBy") && deptObj["createBy"].isString()) {
            dept.createBy = deptObj["createBy"].toString();
        }
        if (deptObj.contains("createTime") && deptObj["createTime"].isString()) {
            dept.createTime = deptObj["createTime"].toString();
        }
        if (deptObj.contains("updateBy") && deptObj["updateBy"].isString()) {
            dept.updateBy = deptObj["updateBy"].toString();
        }
        if (deptObj.contains("updateTime") && deptObj["updateTime"].isString()) {
            dept.updateTime = deptObj["updateTime"].toString();
        }
        if (deptObj.contains("remark") && deptObj["remark"].isString()) {
            dept.remark = deptObj["remark"].toString();
        }
        if (deptObj.contains("deptId") && deptObj["deptId"].isDouble()) {
            dept.deptId = deptObj["deptId"].toInt();
        }
        if (deptObj.contains("parentId") && deptObj["parentId"].isDouble()) {
            dept.parentId = deptObj["parentId"].toInt();
        }
        if (deptObj.contains("ancestors") && deptObj["ancestors"].isString()) {
            dept.ancestors = deptObj["ancestors"].toString();
        }
        if (deptObj.contains("deptName") && deptObj["deptName"].isString()) {
            dept.deptName = deptObj["deptName"].toString();
        }
        if (deptObj.contains("orderNum") && deptObj["orderNum"].isDouble()) {
            dept.orderNum = deptObj["orderNum"].toInt();
        }
        if (deptObj.contains("leader") && deptObj["leader"].isString()) {
            dept.leader = deptObj["leader"].toString();
        }
        if (deptObj.contains("phone") && deptObj["phone"].isString()) {
            dept.phone = deptObj["phone"].toString();
        }
        if (deptObj.contains("email") && deptObj["email"].isString()) {
            dept.email = deptObj["email"].toString();
        }
        if (deptObj.contains("status") && deptObj["status"].isString()) {
            dept.status = deptObj["status"].toString();
        }
        if (deptObj.contains("delFlag") && deptObj["delFlag"].isDouble()) {
            dept.delFlag = deptObj["delFlag"].toInt();
        }
        if (deptObj.contains("parentName") && deptObj["parentName"].isString()) {
            dept.parentName = deptObj["parentName"].toString();
        }
        if (deptObj.contains("children") && deptObj["children"].isArray()) {
            QJsonArray childrenArr = deptObj["children"].toArray();
            for (int i = 0; i < childrenArr.size(); i++) {
                if (childrenArr[i].isObject()) {
                    QJsonObject childObj = childrenArr[i].toObject();
                    Dept childDept = toDept(childObj);
                    dept.children.append(childDept);
                }
            }
        }
        return dept;
    }
};
